package com.sky.controller.user;

import com.sky.dto.order.OrderSubmitDTO;
import com.sky.dto.order.OrdersPaymentDTO;
import com.sky.service.Order.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 褚金龙
 * @Date 2024/10/6 9:15
 */
@RestController("userOrderController")
@RequestMapping("/user")
@CrossOrigin("*")
@Api(tags = "订单相关接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping("/order/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrderSubmitDTO orderSubmitDTO){
          log.info("orderSubmitDTO{}",orderSubmitDTO);
        OrderSubmitVO  orderSubmitVO=  orderService.OrderSubmit(orderSubmitDTO);
          return  Result.success(orderSubmitVO);
    }


    @GetMapping("/order/delete/{orderNumber}")
    @ApiOperation("删除订单")
   public Result deleteOrder(@PathVariable String orderNumber){
         orderService.delete(orderNumber);
      log.info("orderNumber{}",orderNumber);
      return Result.success();
   }

    @PutMapping("/order/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
}
